﻿using Newtonsoft.Json;
namespace LVYAN.Utils
{
    public class JsonService
    {
        public static string ToString<T>(T t)
        {
            if (t == null) return "";
            return JsonConvert.SerializeObject(t);
        }
        public static T ToModel<T>(string data)
        {
            if (string.IsNullOrWhiteSpace(data)) return default;
            return JsonConvert.DeserializeObject<T>(data);
        }
        public static Out ToModel<In, Out>(In t)
        {
            return ToModel<Out>(ToString(t));
        }
    }
}
